package com.sdy.rc.web.controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;

import com.sdy.common.model.BizException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.integration.redis.util.RedisLockRegistry;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sdy.approval.api.ApprovalAllApi;
import com.sdy.approval.biz.model.TpApproveFlow;
import com.sdy.approval.biz.model.TpOrder;
import com.sdy.auth.client.service.SsoService;
import com.sdy.common.model.FileObj;
import com.sdy.common.model.Response;
import com.sdy.common.utils.DateUtil;
import com.sdy.common.utils.StringUtil;
import com.sdy.fs.api.FsApi;
import com.sdy.mvc.controller.BaseController;
import com.sdy.rc.biz.model.MaterialsLibrary;
import com.sdy.rc.biz.model.TMatter;
import com.sdy.rc.biz.service.MaterialsLibraryService;
import com.sdy.rc.biz.service.TMatterService;
import com.sdy.usercenter.api.UserQueryApi;
import com.sdy.usercenter.api.dto.DeptDto;
import com.sdy.usercenter.api.dto.UserDTO;

import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zzq
 * @since 2019-07-11
 */
@Slf4j
@Controller
@RequestMapping("/tMatter")
public class TMatterController extends BaseController {
	@Autowired
	private TMatterService tMatterService;
	@Autowired
	private SsoService ssoService;
	@Autowired
	private MaterialsLibraryService materialsLibraryService;
	@Autowired
	private ApprovalAllApi approvalAllApi;
	@Autowired
	private UserQueryApi userQueryApi;
	@Autowired
	private RedisLockRegistry redisLockRegistry;
	@Value("${file.upload.url}")
	private String filePath;
	@Autowired
	private FsApi fsApi;

	/**
	 * 页面
	 */
	/**
	 * @param req
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/page")
	// @GetMapping("/page")
	public String page(HttpServletRequest req) throws Exception {
		return "/page/t_matter/page";
	}

	/**
	 * 材料详情
	 */
	@GetMapping("/materialDetail")
	public String materialDetail(Model model, Integer id) {
		MaterialsLibrary materialsLibrary = materialsLibraryService.getById(id);
		log.info("materialsLibrary--" + materialsLibrary);
		String uploadFiles = materialsLibraryService.getById(id).getUploadFiles();
		String[] uploadFileId = uploadFiles.split(",");
		List<String> list = new ArrayList<>();
		for (int i = 0; i < uploadFileId.length; i++) {
			String idInt = uploadFileId[i];
			list.add(idInt);
		}
		log.info("fsApi.getFileListInfo(list)--" + fsApi.getFileListInfo(list));
		List<FileObj> listFileInfo = fsApi.getFileListInfo(list);
		log.info("listFileInfo--" + listFileInfo);
		model.addAttribute("param", materialsLibrary);
		model.addAttribute("filePath", filePath);
		return "/page/materials_library/edit";
	}

	/**
	 * 页面导出
	 */
	@GetMapping("/pageOut")
	public String pageOut() {
		return "/page/t_matter/pageOut";
	}

	/**
	 * 新建页面
	 */
	@GetMapping("/newPage")
	public String newPage(HttpServletRequest request, Model model) {
		int userId = ssoService.getUserId(request);
		model.addAttribute("param", userQueryApi.getUser(userId));
		log.info("userQueryApi.getUser(userId)--"+userQueryApi.getUser(userId));
		return "/page/t_matter/new";
	}

	/**
	 * 送审页面
	 */
	@ResponseBody
	@GetMapping("/detailPage")
	public Boolean detailPage(HttpServletRequest request, Integer id, String resId) throws BizException {
		Integer userId = ssoService.getUserInfo(request).getUserId();
		String approvalConfigResId = "[事项录入]";
		// 获取随机申请订单
		long dateEx = System.currentTimeMillis();
		DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		String timeEx = dateFormat.format(dateEx);
		int aEx = (int) (Math.random() * 900 + 100);
		String randomThree = Integer.toString(aEx);
		String randomNum = timeEx + randomThree;
		if (!approvalAllApi.insertRcToOrder(id, resId, userId, randomNum)) {
			return false;
		}
		LambdaUpdateWrapper<TMatter> luwtm = new LambdaUpdateWrapper<>();
		luwtm.eq(TMatter::getId, id).eq(TMatter::getState, 1).set(TMatter::getApprovalState, 1)
				.set(TMatter::getApplyNum, randomNum);
		Boolean luwtmUpdate = tMatterService.update(luwtm);
		if (!luwtmUpdate) {
			return false;
		}
		return true;
	}

	/**
	 * 查询审批页面
	 */
	@GetMapping("/approvalPage")
	public String approvalPage(HttpServletRequest req) throws Exception {
		return "/page/t_matter/auditing";
	}

	/**
	 * 我的审批数据
	 * 
	 * @param request
	 * @param page    [current, size]
	 * @return
	 */
	@GetMapping("/approvalPageData")
	@ResponseBody
	public Response approvalPageData(HttpServletRequest request, Page<TMatter> page) {
		log.info("进入该方法approvalPageData");
		// 事项名搜索
		int key;
		if (null == request.getParameter("result")) {
			key = 1;
		} else {
			key = Integer.valueOf(request.getParameter("result"));
		}
		log.info("key--" + key);
		Integer userId = ssoService.getUserInfo(request).getUserId();
		List<Integer> deptIdList = userQueryApi.getUser(userId).getOwnDeptIdList();
		List<Integer> roldIdList = userQueryApi.getUser(userId).getRoleIdList();
		log.info("deptIdList--" + deptIdList + "--roldIdList--" + roldIdList);
		List<TpOrder> orderList = approvalAllApi.selectTpOrderApprovalToTMatter(deptIdList, roldIdList, key);
		log.info("oList--" + orderList);
		// 如果需要我审批的订单为0
		if (orderList.size() == 0) {
			log.info("111--" + new Page<TMatter>().setSize(page.getSize()).setCurrent(page.getCurrent())
					.setRecords(new ArrayList<TMatter>()));
			return Response.success(new Page<TMatter>().setSize(page.getSize()).setCurrent(page.getCurrent())
					.setRecords(new ArrayList<TMatter>()));
		}

		List<String> resIdList = new ArrayList<>();
		for (int i = 0; i < orderList.size(); i++) {
			String resId = orderList.get(i).getResId();
			resIdList.add(resId);
		}
		log.info("resIdList--" + resIdList);
		LambdaQueryWrapper<TMatter> lqwtm = new LambdaQueryWrapper<>();
		lqwtm.eq(TMatter::getState, 1).in(TMatter::getResId, resIdList).orderByDesc(TMatter::getCreateDate);
		IPage<TMatter> result = tMatterService.page(page, lqwtm);

		log.info("result--" + result);
		result.getRecords();
		log.info("result.getRecords()--" + result.getRecords());
		return Response.success(result);
	}

	/**
	 * 外部审批模态框
	 */
	@GetMapping("/approvalDetail")
	public String approvalDetail(HttpServletRequest req, Integer id, Model model) throws Exception {
		log.info("id--" + id);
		TMatter tMatter = tMatterService.getById(id);
		model.addAttribute("param", tMatter);
		return "/page/t_matter/approvalDetail";
	}

	/**
	 * 执行审批操作(外部)
	 * 
	 * @throws Exception
	 */
	@ResponseBody
	@GetMapping("/approvalUpdate")
	public Response<Boolean> approvalUpdate(HttpServletRequest request, String applyNum, Integer result,
			String auditOpinion) throws Exception {
		log.info("result--" + result + "--auditOpinion--" + auditOpinion + "--applyNum--" + applyNum);
		Integer userId = ssoService.getUserInfo(request).getUserId();
		List<Integer> deptIdList = userQueryApi.getUser(userId).getOwnDeptIdList();
		List<Integer> roldIdList = userQueryApi.getUser(userId).getRoleIdList();
		LambdaQueryWrapper<TMatter> lqwtm = new LambdaQueryWrapper<>();
		lqwtm.eq(TMatter::getApplyNum, applyNum).eq(TMatter::getState, 1);
		String resId = tMatterService.getOne(lqwtm).getResId();
		log.info("resId--" + resId);
		int approvalState = tMatterService.getOne(lqwtm).getApprovalState();
		log.info("approvalState--" + approvalState);
		// 修改TMatter里的状态
		if (result == 2) {
			LambdaUpdateWrapper<TMatter> luwtm = new LambdaUpdateWrapper<>();
			log.info("++++++++++");
			luwtm.eq(TMatter::getApplyNum, applyNum).eq(TMatter::getState, 1).set(TMatter::getApprovalState,
					approvalState + 1);
			Boolean updateApprovalState = tMatterService.update(luwtm);
			if (!updateApprovalState) {
				log.info("审批时修改TMatter错误,通过");
				return Response.error();
			}
		} else if (result == 3) {
			LambdaUpdateWrapper<TMatter> luwtm = new LambdaUpdateWrapper<>();
			luwtm.eq(TMatter::getApplyNum, applyNum).eq(TMatter::getState, 1).set(TMatter::getApprovalState, 8);
			Boolean updateApprovalState = tMatterService.update(luwtm);
			if (!updateApprovalState) {
				log.info("审批时修改TMatter错误，驳回");
				return Response.error();
			}
		}
		TpApproveFlow tpApproveFlow = new TpApproveFlow();
		tpApproveFlow.setUserId(userId).setResult(result).setApplyId(applyNum).setResId(resId);
		log.info("deptIdList--" + deptIdList + "--roldIdList--" + roldIdList + "--tpApproveFlow--" + tpApproveFlow);
		if (!approvalAllApi.updateNodeApprovalResults(tpApproveFlow, deptIdList, roldIdList).equals("已审批")) {
			log.info("审批TMatter时，节点审批出错");
			return Response.error();
		}
		return Response.success(true);
	}

	/**
	 * 查询审批详情页面
	 */
	@GetMapping("/approvalDetailLook")
	public String approvalDetailLook(Model model, Integer id, Integer result) throws Exception {
		log.info("进入approvalDetailLook方法id" + id + "--result--" + result);
		TMatter tMatter = tMatterService.getById(id);
		model.addAttribute("param", tMatter);
		return "/page/t_matter/approvalDetailTMatter";
	}

	/**
	 * 节点信息查询
	 * 
	 * @param request
	 * @return
	 */
	@GetMapping("/approvalNodeData")
	@ResponseBody
	public Response approvalNodeData(HttpServletRequest request, String applyNum) {
		List<TpApproveFlow> tpApproveFlowList = approvalAllApi.selectApprovalFlowByTMatterResId(applyNum);
		//暂存部门名称操作
		List<Integer> deptIdList = tpApproveFlowList.stream().map(TpApproveFlow::getApprovalDeptId).collect(Collectors.toList());
		List<DeptDto> listDeptByIds = userQueryApi.listDeptByIds(deptIdList);
		for (TpApproveFlow tp : tpApproveFlowList) {
			for (DeptDto dept : listDeptByIds) {
				if (tp.getApprovalDeptId().equals(dept.getId())) {
					tp.setDeptName(dept.getName());
				}
			}
		}
		//暂存审批人名称操作
		List<Integer> modifyUserIdList = tpApproveFlowList.stream().map(TpApproveFlow::getModifyUser).collect(Collectors.toList());
		List<UserDTO> listUser = userQueryApi.listUser(modifyUserIdList);
		log.info("modifyUserIdList--"+modifyUserIdList+"--listUser--"+listUser);
		for(TpApproveFlow tp : tpApproveFlowList) {
			for(UserDTO user : listUser) {
				if(tp.getModifyUser() != null && tp.getModifyUser().equals(user.getId())) {
					tp.setApprovalName(user.getName());
				}
			}
		}
		log.info("-----///----"+tpApproveFlowList);
		return Response.success(tpApproveFlowList);
	}

	/**
	 * 当前用户节点审批结果
	 * 
	 * false:未审批 true：已审批
	 * 
	 */
	@GetMapping("/approvalNodeResult")
	@ResponseBody
	public Boolean approvalNodeResult(HttpServletRequest request, String applyNum) {
		log.info("进入approvalNodeResult方法");
		Integer userId = ssoService.getUserInfo(request).getUserId();
		List<Integer> deptIdList = userQueryApi.getUser(userId).getOwnDeptIdList();
		List<Integer> roldIdList = userQueryApi.getUser(userId).getRoleIdList();
		TpApproveFlow tpApproveFlow = approvalAllApi.selectApprovalFlowResultByResId(applyNum, deptIdList, roldIdList);
		int result = tpApproveFlow.getResult();
		if (result == 2 || result == 3) {
			log.info("result == 2 || result == 3");
			return true;
		}
		return false;
	}

	/**
	 * 修改页面
	 */
	@GetMapping("/updatePage")
	public String updatePage(Model model, Integer id) {
		TMatter tMatter = tMatterService.getById(id);
		// 获取本地市民材料信息
		String materialsListLocal = tMatter.getMaterialsListLocal();
		List<MaterialsLibrary> list2 = new ArrayList<>();
		if (StringUtil.isNotBlank(materialsListLocal)) {
			String[] idLocal = materialsListLocal.split(";");
			// 如果该字段存储了数据的id
			List<Integer> list = new ArrayList<>();
			for (int i = 0; i < idLocal.length; i++) {
				int idInt = Integer.valueOf(idLocal[i]);
				list.add(idInt);
			}
			LambdaQueryWrapper<MaterialsLibrary> lqwml = new LambdaQueryWrapper<>();
			lqwml.in(MaterialsLibrary::getId, list);
			list2 = materialsLibraryService.list(lqwml);
		}

		// 获取非本地市民材料信息
		String materialsListOutside = tMatter.getMaterialsListOutside();
		List<MaterialsLibrary> list3 = new ArrayList<>();
		if (StringUtil.isNotBlank(materialsListOutside)) {
			String[] idOutside = materialsListOutside.split(";");
			// 如果该字段存储了数据的id
			List<Integer> listOutside = new ArrayList<>();
			for (int i = 0; i < idOutside.length; i++) {
				int idIntOutSide = Integer.valueOf(idOutside[i]);
				listOutside.add(idIntOutSide);
			}
			LambdaQueryWrapper<MaterialsLibrary> lqwml2 = new LambdaQueryWrapper<>();
			lqwml2.in(MaterialsLibrary::getId, listOutside);
			list3 = materialsLibraryService.list(lqwml2);
		}
		model.addAttribute("mPara", list2);
		model.addAttribute("mPara2", list3);
		model.addAttribute("param", tMatter);
		return "/page/t_matter/update";
	}

	/**
	 * 分页数据
	 * 
	 * @param request
	 * @param page    [current, size]
	 * @return
	 */
	@GetMapping("/pageData")
	@ResponseBody
	public Response pageData(HttpServletRequest request, Page<TMatter> page) {
		QueryWrapper<TMatter> wrapper = new QueryWrapper<>();

		// 事项名搜索
		String key = request.getParameter("key");
		wrapper.like(StringUtils.isNotBlank(key), "matter_name", key);

		// 状态搜索
		String id = request.getParameter("id");
		wrapper.eq(StringUtils.isNotBlank(id), "public_service_flag", id);

		// 是否进驻市民之家搜索
		String publicServiceFlag = request.getParameter("publicServiceFlag");
		wrapper.eq(StringUtils.isNotBlank(publicServiceFlag), "public_service_flag", publicServiceFlag);

		// 是否被隐藏
		String state = request.getParameter("state");
		wrapper.eq(StringUtils.isNotBlank(state), "state", state);

		// 创建时间搜索
		String createTime = request.getParameter("createTime");
		log.info("createTime--"+createTime);
		String createTimeRange = request.getParameter("createTimeRange");
		if (StringUtils.isNotBlank(createTime)) {
			wrapper.ge("create_date", DateUtil.getDate(createTime + " 00:00:00", DateUtil.DATETIME_FORMAT));
		}
		if (StringUtils.isNotBlank(createTimeRange)) {
			wrapper.le("create_date", DateUtil.getDate(createTimeRange + " 23:59:59", DateUtil.DATETIME_FORMAT));
		}

		wrapper.orderByDesc("id");
		IPage<TMatter> result = tMatterService.page(page, wrapper);
		log.info("result-----" + result);

		return Response.success(result);
	}

	/**
	 * 分页数据(事项导出)
	 * 
	 * @param request
	 * @param page
	 * @param limit
	 * @return
	 */
	@GetMapping("/pageJSONData")
	@ResponseBody
	public String pageJSONData(HttpServletRequest request, Integer page, Integer limit) {
		QueryWrapper<TMatter> wrapper = new QueryWrapper<>();
		wrapper.eq("state", 1);
		wrapper.orderByDesc("id");
		List<TMatter> list = tMatterService.list(wrapper);
		log.info("list--"+list);
		for (TMatter tMatter2 : list) {
			
				tMatter2.setRemarks(tMatter2.getRemarks().replaceAll("#replace#", "\n"));
				log.info("--tMatter2.getSpecificTerms()--"+tMatter2.getSpecificTerms());
				if(tMatter2.getSpecificTerms() != null) {
					log.info("--11--");
					tMatter2.setSpecificTerms(tMatter2.getSpecificTerms().replaceAll("#replace#", "\n"));
				}
		}
		IPage<TMatter> result = new IPage<TMatter>() {

			@Override
			public List<TMatter> getRecords() {

				return list.subList(limit * (page - 1), list.size() >= limit * page ? limit * page : list.size());
			}

			@Override
			public IPage<TMatter> setRecords(List<TMatter> records) {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public long getTotal() {
				// TODO Auto-generated method stub
				return list.size();
			}

			@Override
			public IPage<TMatter> setTotal(long total) {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public long getSize() {
				// TODO Auto-generated method stub
				return limit;
			}

			@Override
			public IPage<TMatter> setSize(long size) {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public long getCurrent() {
				// TODO Auto-generated method stub
				return page;
			}

			@Override
			public IPage<TMatter> setCurrent(long current) {
				// TODO Auto-generated method stub
				return null;
			}
		};

		JSONObject json = new JSONObject();
		json.put("code", 0);
		json.put("msg", "");
		json.put("count", result.getTotal());
		json.put("data", JSON.parseArray(JSON.toJSONString(result.getRecords())));
		return json.toString();
	}

	/**
	 * 导出全业数据
	 * 
	 * @param
	 * @return
	 */
	@GetMapping("/pageExcel")
	@ResponseBody
	public String pageExcel(TMatter tMatter, HttpServletRequest request) {
		// 注意layui的数据接收格式
		List<TMatter> list = tMatterService.findAllTMatter();
		for (TMatter tMatter2 : list) {
			tMatter2.setRemarks(tMatter2.getRemarks().replaceAll("#replace#", "\n"));
			if(tMatter2.getSpecificTerms() != null) {
				tMatter2.setSpecificTerms(tMatter2.getSpecificTerms().replaceAll("#replace#", "\n"));
			}
		}
		JSONArray array = JSON.parseArray(JSON.toJSONString(list));
		for (int i = 0; i < array.size(); i++) {
			JSONObject obje = array.getJSONObject(i);
			// 事项属性
			if (obje.getInteger("matterAttr") == 1) {
				obje.put("matterAttr", "公共服务");
			} else {
				obje.put("matterAttr", "权力事项");
			}
			// 在社区办理：注明直接办理、委托办理
			if (obje.getString("wayCommunityHandle") == null) {
				obje.put("wayCommunityHandle", "");
			} else if (obje.getString("wayCommunityHandle").equals("1")) {
				obje.put("wayCommunityHandle", "直接办理");
			} else if (obje.getString("wayCommunityHandle").equals("2")) {
				obje.put("wayCommunityHandle", "委托办理");
			} else if (obje.getString("wayCommunityHandle").equals("")) {
				obje.put("wayCommunityHandle", "");
			}
			// 是否可以“实现最多跑一次”
			String onceFlag = obje.getString("onceFlag");
			if (onceFlag != null && onceFlag.equals("1")) {
				obje.put("onceFlag", "是");
			} else if (onceFlag != null && onceFlag.equals("2")) {
				obje.put("onceFlag", "否");
			}

			// 是否仅需身份证或市民卡就可办理
			if (obje.getString("idcardFlag").equals("1")) {
				obje.put("idcardFlag", "已可");
			} else if (obje.getString("idcardFlag").equals("2")) {
				obje.put("idcardFlag", "拟可");
			} else if (obje.getString("idcardFlag").equals("3")) {
				obje.put("idcardFlag", "不可");
			}
			// 是否有自助端，配置点地址
			if (obje.getString("selfServiceFlag").equals("1")) {
				obje.put("selfServiceFlag", "是；" + obje.getString("selfServiceAddr"));
			} else if (obje.getString("selfServiceFlag").equals("2")) {
				obje.put("selfServiceFlag", "否");
			}
			//// 是否有业务咨询网站：若有请注明网址
			if (obje.getInteger("bizConsultingWebFlag") == 1) {
				obje.put("bizConsultingWebFlag", "是；" + obje.getString("bizConsultingWebAddr"));
			} else if (obje.getInteger("bizConsultingWebFlag") == 2) {
				obje.put("bizConsultingWebFlag", "否");
			}
			// 业务咨询电话是否归入12345：若否请注明电话
			if (obje.getInteger("bringHotlineFlag") == 1) {
				obje.put("bringHotlineFlag", "是");
			} else if (obje.getInteger("bringHotlineFlag") == 2) {
				obje.put("bringHotlineFlag", "否；" + obje.getString("bizConsultingHotline"));
			}
			// 是否仅需身份证或市民卡就可办理
			String fieldIdcardFlagNow = obje.getString("fieldIdcardFlagNow");
			if (fieldIdcardFlagNow != null && fieldIdcardFlagNow.equals("1")) {
				obje.put("fieldIdcardFlagNow", "是");
			} else if (fieldIdcardFlagNow != null && fieldIdcardFlagNow.equals("2")) {
				obje.put("fieldIdcardFlagNow", "否");
			}
		}
		JSONObject json = new JSONObject();
		json.put("code", 0);
		json.put("msg", "");
		json.put("count", list.size());
		json.put("data", array);
		return json.toString();
	}

	/**
	 * 保存数据
	 * 
	 * @param
	 * @return
	 */
	@PostMapping("/save")
	@ResponseBody
	public Response save(TMatter tMatter, HttpServletRequest request, Integer userId) {
		tMatter.setRemarks(tMatter.getRemarks().replaceAll("\r|\n", "#replace#"));
		tMatter.setSpecificTerms(tMatter.getSpecificTerms().replaceAll("\r|\n", "#replace#"));

		if (tMatter.getCreateDate() == null) {
			tMatter.setCreateDate(new Date());
		}
		tMatterService.save(tMatter);
		log.info("tMatter.getId()--" + tMatter.getId());
		tMatter.setResId("[事项录入]" + tMatter.getId());
		tMatter.setCreateUser(ssoService.getUserInfo(request).getUserId());
		return Response.success(tMatterService.updateById(tMatter));
	}

	/**
	 * 更新数据
	 * 
	 * @param
	 * @return
	 */
	@PostMapping("/update")
	@ResponseBody
	public Response update(TMatter tMatter, HttpServletRequest request, Integer userId) {
		tMatter.getHandleDeptLevel();
		log.info("tMatter.getHandleDeptLevel()--"+tMatter.getHandleDeptLevel());
		//复选框取消选择后的传值
		if(tMatter.getHandleDeptLevel() == null) {
			log.info("111");
			tMatter.setHandleDeptLevel("");
		}
		if(tMatter.getMatterType() == null) {
			tMatter.setMatterType("");
		}
		if(tMatter.getOnlineHandleTypeReform() == null) {
			tMatter.setOnlineHandleTypeReform("");
		}
		if(tMatter.getHandleChannelReform() == null) {
			tMatter.setHandleChannelReform("");
		}
		if(tMatter.getIdcardType() == null) {
			tMatter.setIdcardType("");
		}
		if(tMatter.getFieldDevices() == null) {
			tMatter.setFieldDevices("");
		}
		if(tMatter.getElectronicArchivingType() == null) {
			tMatter.setElectronicArchivingType("");
		}
		if(tMatter.getSystemOrigin() == null) {
			tMatter.setSystemOrigin("");
		}
		if(tMatter.getSelfServiceFunc() == null) {
			tMatter.setSelfServiceFunc("");
		}
		tMatter.setRemarks(tMatter.getRemarks().replaceAll("\r|\n", "#replace#"));
		tMatter.setSpecificTerms(tMatter.getSpecificTerms().replaceAll("\r|\n", "#replace#"));
		tMatter.setModifyDate(new Date());
		tMatter.setModifyUser(ssoService.getUserInfo(request).getUserId());
		return Response.success(tMatterService.updateById(tMatter));
	}

	/**
	 * 删除数据
	 * 
	 * @param id 主键
	 * @return
	 */
	@GetMapping("/delete")
	@ResponseBody
	public Response delete(Integer id) {
		// return Response.success(tMatterService.removeById(id));

		// 删除（隐藏数据）单条
		return Response.success(tMatterService.concealMatterspersonalById(id));
	}

	/**
	 * 删除数据
	 * 
	 * @param id 主键
	 * @return
	 */
	@GetMapping("/deleteBatch")
	@ResponseBody
	public Response deleteBatch(Integer[] id) {
		if (id != null) {
			// tMatterService.removeByIds(Arrays.asList(id));
			for (Integer matterId : id) {
				TMatter tmatter = tMatterService.getById(matterId);
				tmatter.setState(Integer.valueOf(2));
				tMatterService.updateById(tmatter);
			}
			// tMatterService.concealMatterspersonalByIds(Arrays.asList(id));
		}
		return Response.success();
	}
}
